package us.nchu.tomtiger.dao;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import us.nchu.tomtiger.model.UserShow;
import us.nchu.tomtiger.rowMapper.UserShowRowMapper;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by XiongXuan on 2018/1/8.
 */
@Repository
public class UserShowDao {

    @Resource
    private JdbcTemplate jdbcTemplate;

    public boolean insert(UserShow userShow) {
        String sql = "insert into student_show(phone_number) values(?);";
        return jdbcTemplate.update(sql, new Object[]{userShow.getPhoneNumber()}) > 0;
    }

    public UserShow queryByShowId(String userShowId) {
        String sql = "select * from student_show where id=" + userShowId + ";";
        return (UserShow)jdbcTemplate.queryForObject(sql, new UserShowRowMapper());
    }

    public UserShow queryByUserId(String phoneNumber) {
        String sql = "select * from student_show where phone_number=" + phoneNumber + ";";
        return (UserShow)jdbcTemplate.queryForObject(sql, new UserShowRowMapper());
    }
}
